# 博弈论的题目，分为两种，一种考虑之前操作过的东西，这种一般用记忆化搜索或者DP；其次还有一种只考虑最后情况，这种可以用SG函数。SG函数定义：最小非负整数值，其中0为必败态，其他为必胜态
# source:https://www.lanqiao.cn/problems/113/learning/?page=1&first_category_id=1&second_category_id=3&tags=%E5%8D%9A%E5%BC%88&tag_relation=intersection 
import os
import sys
from functools import lru_cache
from math import inf
# 请在此输入您的代码
n = int(input())

@lru_cache(None)
def dfs(s, is_my_turn):
    if ('L*L' in s) or ('*OL' in s) or ('LO*' in s):
        return 1 if is_my_turn else -1
    res = -inf if is_my_turn else inf
    for i, v in enumerate(s):
        if v == '*':
            for sign in ['O','L']:
                ans = dfs(s[:i]+sign+s[i+1:], not is_my_turn)
                if is_my_turn:
                    res = max(res, ans)
                else:
                    res = min(res, ans)
    if res == -inf or res == inf:
        return 0
    return res

for _ in range(n):
    s = input().strip()
    if ('L*L' in s) or ('*OL' in s) or ('LO*' in s):
        print(1)
        continue
    res = dfs(s, 1)
    print(res)

# source: https://www.lanqiao.cn/problems/123/learning/?page=1&first_category_id=1&second_category_id=3&tags=%E5%8D%9A%E5%BC%88&tag_relation=intersection 记忆化搜索
import sys
sys.setrecursionlimit(10000)

# 可取的球数
take_options = list(map(int, input().split()))
game_starts = list(map(int, input().split()))

# 记忆化：缓存结果
# 状态：(剩余球数, 当前我的球数, 当前对手的球数, 当前是否我在操作)
from functools import lru_cache

@lru_cache(None)
def dfs(remaining, my, opponent, is_my_turn):
    if remaining < min(take_options):
        # 没球可取了，判断结果
        if (my % 2 == 1 and opponent % 2 == 1) or (my % 2 == 0 and opponent % 2 == 0):
            return 0  # 平局
        elif my % 2 == 1:
            return 1  # 我赢
        else:
            return -1  # 我输

    result_set = set()
    for take in take_options:
        if take <= remaining:
            if is_my_turn:
                result = dfs(remaining - take, my ^ (take % 2), opponent, not is_my_turn)
            else:
                result = dfs(remaining - take, my, opponent ^ (take % 2), not is_my_turn)
            result_set.add(result)

    # 如果我是当前操作方，我希望：
    if is_my_turn:
        return max(result_set)
    else:
        return min(result_set)
    
# 输出结果
ans = []
for start in game_starts:
    res = dfs(start, 0, 0, True)  # 我是先手
    if res == 1:
        ans.append("+")
    elif res == 0:
        ans.append("0")
    else:
        ans.append("-")

print(' '.join(ans))

# source: https://www.lanqiao.cn/problems/19722/learning/ DP SG
import os
import sys

# 请在此输入您的代码
N = 10**5+1
dp = [0]*N
prime = [True]*(N)
seive = []
for i in range(2, 10**5+1):
     if prime[i]:
          seive.append(i)
     for p in seive:
          if i * p >= N:
               break
          prime[i*p] = False
          if i % p == 0:
               break
for i in range(2, N):
     for j in seive:
          if i - j >= 0:
               if dp[i-j] == 0:
                    dp[i] = 1
                    break
          else:
               break

T = int(input())
for _ in range(T):
     print(dp[int(input())])

# source:https://leetcode.cn/problems/stone-game/ 记忆化搜索
# from functools import cache
# class Solution:
#     def stoneGame(self, piles: List[int]) -> bool:
#         @cache
#         def dfs(i, j, A, B):
#             is_alice = (j-i+1) % 2
#             if i > j:
#                 return 1 if A > B else -1
#             res = -inf if is_alice else inf
#             for k in range(2):
#                 if is_alice:
#                     if k == 0:
#                         res = max(res, dfs(i+1, j, A+piles[i], B))
#                     else:
#                         res = max(res, dfs(i, j-1, A+piles[j], B))
#                 else:
#                     if k == 0:
#                         res = min(res, dfs(i+1, j, A, B+piles[i]))
#                     else:
#                         res = min(res, dfs(i, j-1, A, B+piles[j]))    
#             return res
#         return bool(dfs(0, len(piles)-1, 0, 0))

from functools import cache
class Solution:
    def stoneGame(self, piles: List[int]) -> bool:
        @cache
        def dfs(i: int, j: int) -> int:
            if i > j:
                return 0
            # If (j-i) is even, it's Alice's turn; if odd, it's Bob's turn
            is_alice = (j - i + 1) % 2 == 0
            if is_alice:
                # Alice maximizes her score
                return max(piles[i] + dfs(i + 1, j), piles[j] + dfs(i, j - 1))
            else:
                # Bob minimizes Alice's score
                return min(dfs(i + 1, j), dfs(i, j - 1))
        
        n = len(piles)
        total = sum(piles)
        alice_score = dfs(0, n - 1)
        return alice_score > total - alice_score